package com.iMANIT.DS.DubLinkedList
{
	import com.iMANIT.OO.ThisIs;
	
	public final class DLLnodeFactory
	{
		protected var pool:DLLnodePool;
		
		public function create(payload:*):DLLnode
		{
			var node:DLLnode;
				if (pool.length > 0)
				{
					node = pool.borrowNode(payload);
					
				}
				else
				{
					node = new DLLnode(payload);
				}
				return node;
		}
		
		public function dispose(n:DLLnode):void
		{
			pool.returnNode(n);
		}
		
		
		
		
		
		
		
		
		////////singelton stuff.
		private static var _instance:DLLnodeFactory;
		private static var _lock:Boolean = true;
		public function DLLnodeFactory()
		{
			if (_lock)
			{
				ThisIs.aSingeltonClass();
			}
			pool = new DLLnodePool();
		}

		public static function getInstance():DLLnodeFactory
		{
			if (!_instance)
			{
				_lock = false;
				_instance = new DLLnodeFactory();
				_lock = true;
			}
			return _instance;
		}
	}
}